﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_TraAddbid : System.Web.UI.Page,HZ.MBSM.BLL.TraDes
{
    public string _strProjectId = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {

            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
              

               
                if (!IsPostBack)
                {
                    Db db = new Db();
                    string strSql = "select projectid,ProjectMarker,Title from project order by projectid desc";
                    System.Data.IDataReader dr = db.DataReader(strSql);
                    listProject.DataSource = dr;
                    listProject.DataTextField = "Title";
                    listProject.DataValueField = "projectid";
                    listProject.DataBind();
                    dr.Close();
                    dr.Dispose();
                    db.Close();
                }
                _strProjectId = listProject.SelectedValue;
                string projectid1 = SysFun.IsSQL(Request.QueryString["ProjectId"].ToString());
                if (projectid1 == "9")
                {
                    this.Label3.Visible = true;
                }
                else
                {
                    this.Label3.Visible = false;
                }

    
                

            }
        }
    }

    #region TraDes 成员

    public string Name
    {
        get { return "挂网目录管理"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "挂网目录管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            return _AccountType;
        }
    }


    #endregion
    protected void Button2_Click(object sender, EventArgs e)//查询是否已存在
    {
    
        if (SysFun.IsNumeric(TextBox1.Text.Trim()))
        {
            string strselect = "select 1 as bidid, case projectid when 8 then '原中标'  when 9 then '自行采购' when 10 then '22种降价' when 11 then '血液制品' when 12 then '重点监控' end as projectid,goodsid,productname,medicinemodel,outlookc,unit,factor,companyname_sc,companyname_tb,companyname_ps,bidprice,case isuse when 1 then '可交易' else '撤废' end as isuse,RetailPrice from SupplyPlan_Goods where goodsid=" + TextBox1.Text.Trim();
            Db db = new Db();
            DataTable dt = db.DataTable(strselect);
            db.Close();
            if (dt.Rows.Count > 0)
            {
                Button3.Enabled = false;
                Button4.Visible = false;
                switch (dt.Rows[0][1].ToString())
                {
                    case "原中标":
                        GridView1.Columns[10].Visible = true;
                        GridView1.Columns[11].Visible = true ;
                        GridView1.Columns[10].HeaderText = "挂网价";
                        GridView1.Columns[11].HeaderText = "最高临售价";
                        break;
                    case "自行采购":
                        GridView1.Columns[10].Visible = true ;
                        GridView1.Columns[11].Visible = false;
                        GridView1.Columns[10].HeaderText = "最高临售价";
                        Button3.Enabled = true ;
                        Button4.Visible = true;
                        break;
                    case "22种降价":
                        GridView1.Columns[10].Visible = true;
                        GridView1.Columns[11].Visible = true;
                        GridView1.Columns[10].HeaderText = "最高限价";
                        GridView1.Columns[11].HeaderText = "最高临售价";
                        break;
                    case "血液制品":
                        GridView1.Columns[10].Visible = false;
                        GridView1.Columns[11].Visible = false;
                        break;
                    case "重点监控":
                        GridView1.Columns[10].Visible = true ;
                        GridView1.Columns[11].Visible = false;
                        GridView1.Columns[10].HeaderText = "最高临售价";
                        break;
                }
                GridView1.Columns[13].Visible = false;
                GridView1.DataSource = dt;
                GridView1.DataBind();

                Label1.Visible = true;
               
            
            
    
            }
            else
            {
                 Response.Write("<script>alert('恭喜你！此流水号未中标！');</script>");
                 strselect = "select bidid, case projectid when 8 then '原中标'  when 9 then '自行采购' when 10 then '22种降价' when 11 then '血液制品' when 12 then '重点监控' end as projectid,goodsid,productname,medicinemodel,outlookc,unit,factor,companyname_sc,companyname_tb,1 as companyname_ps,bidprice,0 as isuse,RetailPrice from Bid_goods_product_cs_tb_agent where goodsid=" + TextBox1.Text.Trim() + " and  convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) not in(select convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) from SupplyPlan_Goods)";
                 db = new Db();
                 dt = db.DataTable(strselect);
                db.Close();
                if (dt.Rows.Count > 0)
                {
                    switch (listProject.SelectedValue)
                    {
                        case "8":
                            GridView1.Columns[10].Visible = true ;
                            GridView1.Columns[11].Visible = true ;
                            GridView1.Columns[10].HeaderText = "挂网价";
                            GridView1.Columns[11].HeaderText = "最高临售价";
                            break;
                        case "9":
                            GridView1.Columns[10].Visible = true ;
                            GridView1.Columns[11].Visible = false;
                            GridView1.Columns[11].HeaderText = "最高临售价";
                            break;
                        case "10":
                            GridView1.Columns[10].Visible = true ;
                            GridView1.Columns[11].Visible = true ;
                            GridView1.Columns[10].HeaderText = "最高限价";
                            GridView1.Columns[11].HeaderText = "最高临售价";
                            break;
                        case "11":
                            GridView1.Columns[10].Visible = false;
                            GridView1.Columns[11].Visible = false;
                            break;
                        case "12":
                            GridView1.Columns[10].Visible = true ;
                            GridView1.Columns[11].Visible = false;
                            GridView1.Columns[10].HeaderText = "最高临售价";
                            break;
                    }
                    GridView1.Columns[13].Visible = true ;
                    Label1.Visible = true;
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    Button3.Enabled = true;
                  
                }
                else
                {
                    Label1.Visible = false;
                    Button3.Enabled = false;

                    Response.Write("<script>alert('无效流水号或该流水号的投标人已都中标！');</script>");
                }

                
            }
        }
        else
        {
            Response.Write("<script>alert('别开玩笑！流水号要是数字的！');</script>");
        }
    }
    protected void Button3_Click(object sender, EventArgs e) //导入
    {
        string _goodsstatus = "0",  strSql="" ;
        if (Request["chk"] != null && Request["chk"] != "")
        {
            _strProjectId = listProject.SelectedValue;
            switch (_strProjectId)
            {
                case "8":
                    _goodsstatus = "0";
                    strSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName,PS_ChangeStatus) select " + _strProjectId + ", ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_tb, CompanyName_tb,BidPrice,'" + _goodsstatus + "',UserCode_TB,UserCode_tb,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName ,0 from Bid_goods_product_cs_tb_agent where  bidid in(" + Request["chk"] + ") and  convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) not in(select convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) from SupplyPlan_Goods)";
                    break;
                case "9":
                    _goodsstatus = "1";
                    strSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName,PS_ChangeStatus) select " + _strProjectId + ", ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_tb, CompanyName_tb,RetailPrice,'" + _goodsstatus + "',UserCode_TB,UserCode_tb,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName ,0 from Bid_goods_product_cs_tb_agent where  bidid in(" + Request["chk"] + ") and  convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) not in(select convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) from SupplyPlan_Goods)";
                  
                    break;
                case "10":
                    _goodsstatus = "2";
                    strSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice,RetailPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName,PS_ChangeStatus) select " + _strProjectId + ", ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_tb, CompanyName_tb,BidPrice,RetailPrice,'" + _goodsstatus + "',UserCode_TB,UserCode_tb,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName ,0 from Bid_goods_product_cs_tb_agent where  bidid in(" + Request["chk"] + ") and  convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) not in(select convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) from SupplyPlan_Goods)";
                  
                    break;
                case "11":
                    _goodsstatus = "3";
                    strSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName,PS_ChangeStatus) select " + _strProjectId + ", ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_tb, CompanyName_tb,'" + _goodsstatus + "',UserCode_TB,UserCode_tb,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName ,0 from Bid_goods_product_cs_tb_agent where  bidid in(" + Request["chk"] + ") and  convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) not in(select convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) from SupplyPlan_Goods)";
                    break;
                case "12":
                    _goodsstatus = "4";
                    strSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName,PS_ChangeStatus) select " + _strProjectId + ", ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_tb, CompanyName_tb,RetailPrice,'" + _goodsstatus + "',UserCode_TB,UserCode_tb,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName ,0 from Bid_goods_product_cs_tb_agent where  bidid in(" + Request["chk"] + ") and  convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) not in(select convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) from SupplyPlan_Goods)";
                    break;
            }
            Db db = new Db();
            db.Command(strSql, 30);
            strSql = "update project_bid set checkstatus=1 where bidid in(" + Request["chk"] + ")";
            db.Command(strSql, 30);
            Response.Write("<script>alert('添加成功！');</script>");

            db.Close();
        }
        else
        {
            Response.Write("<script>alert('请选择！');</script>");
        }
    }
    protected void Button4_Click(object sender, EventArgs e) //更状态新
    {
        if (Request["chk"] != null && Request["chk"] != "")
        {
            Db db = new Db();

            string strSql = "update project_bid set checkstatus=1 where bidid in(" + Request["chk"] + ")";
            db.Command(strSql, 30);
            db.Close();
            Response.Write("<script>alert('添加成功！');</script>");
        }
        else
        {
            Response.Write("<script>alert('请选择！');</script>");
        }
       
    }
    protected void Button4_Click1(object sender, EventArgs e) //查看投标
    {

       
        string strselect = "select bidid, case projectid when 8 then '原中标'  when 9 then '自行采购' when 10 then '22种降价' when 11 then '血液制品' when 12 then '重点监控' end as projectid,goodsid,productname,medicinemodel,outlookc,unit,factor,companyname_sc,companyname_tb,1 as companyname_ps,bidprice,0 as isuse,RetailPrice from Bid_goods_product_cs_tb_agent where UserCode_TB=" + TextBox1.Text.Trim() + " and  convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) not in(select convert(varchar(50),goodsid)+convert(varchar(50),accountid_tb) from SupplyPlan_Goods)";
        Db  db = new Db();
        DataTable dt = db.DataTable(strselect);
        db.Close();
        if (dt.Rows.Count > 0)
        {
            switch (listProject.SelectedValue)
            {
                case "8":
                    GridView1.Columns[10].Visible = true ;
                    GridView1.Columns[11].Visible = true ;
                    GridView1.Columns[10].HeaderText = "挂网价";
                    GridView1.Columns[11].HeaderText = "最高临售价";
                    break;
                case "9":
                    GridView1.Columns[10].Visible =false;
                    GridView1.Columns[11].Visible = true;
                    GridView1.Columns[11].HeaderText =  "最高临售价";
                    break;
                case "10":
                    GridView1.Columns[10].Visible = true ;
                    GridView1.Columns[11].Visible = true ;
                    GridView1.Columns[10].HeaderText = "最高限价";
                    GridView1.Columns[11].HeaderText = "最高临售价";
                    break;
                case "11":
                    GridView1.Columns[10].Visible = false;
                    GridView1.Columns[11].Visible = false;
                    break;
                case "12":
                    GridView1.Columns[10].Visible = true ;
                    GridView1.Columns[11].Visible = false;
                    GridView1.Columns[10].HeaderText = "最高临售价";
                    break;
            }
            GridView1.Columns[13].Visible = true;
            Label1.Visible = true;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            Button3.Enabled = true;

        }
        else
        {
            Label1.Visible = false;
            Button3.Enabled = false;

            Response.Write("<script>alert('无效流水号或该流水号的投标人已都中标！');</script>");
        }

    }


    protected void ButtonQuery_Click(object sender, EventArgs e) 
    {



        string sql = "select  goodsid,productname,medicinemodel,outlookc,unit,factor,companyname_sc,companyname_tb,RetailPrice from dbo.Bid_goods_product_cs_tb_agent where UserCode_TB='" + this.TextBox2.Text.ToString() + "' and projectid='9' and  goodsid not in(select goodsid from SupplyPlan_Goods where UserCode_TB='" + this.TextBox2.Text.ToString() + "') and checkstatus_goods=1 ";

        Db db = new Db();

        DataTable dt = db.DataTable(sql);
        db.Close();
        if(dt.Rows.Count==0)
        {
            Response.Write("<Script>alert('没有记录')</script>");

        }
        else
        {
            this.GridView2.DataSource = dt;
            this.GridView2.DataBind();
            this.Button7.Visible = true;
        }

        this.Label3.Visible = true;
        
       

    }
    protected void daoru_Click(object sender, EventArgs e) //查看投标
    {



        string strSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName)select projectid, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, AccountId_TB, CompanyName_TB, AccountId_tb, CompanyName_tb,RetailPrice,checkstatus_goods,UserCode_TB,UserCode_tb,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName  from Bid_goods_product_cs_tb_agent where   UserCode_TB='" + this.TextBox2.Text.ToString() + "' and   goodsid not in(select goodsid from SupplyPlan_Goods where UserCode_TB='" + this.TextBox2.Text.ToString() + "') and projectid=9 and checkstatus_goods=1";

        Db db = new Db();

      int  number1=db.Command(strSql);

        db.Close();
        Response.Write("<script>alert('导入"+number1+"条数据')</script>");
         
        this.Label3.Visible = true;


    }




    
}
